/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newkfp;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author $alama
 */
@Entity
@Table(name = "item")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Item.findAll", query = "SELECT i FROM Item i"),
    @NamedQuery(name = "Item.findByIdItem", query = "SELECT i FROM Item i WHERE i.idItem = :idItem"),
    @NamedQuery(name = "Item.findByItemName", query = "SELECT distinct i FROM Item i WHERE i.itemName like :itemName"),
    @NamedQuery(name = "Item.findItemType", query = "SELECT distinct i.itemName FROM Item i"),
    @NamedQuery(name = "Item.findByItemType", query = "SELECT distinct i FROM Item i WHERE i.itemType = :itemType"),
    @NamedQuery(name = "Item.findByItemNameAndFactoryIDAndCountryID", query = "SELECT i FROM Item i WHERE   i.itemName = :itemName AND i.factoryID = :factoryID "),
    @NamedQuery(name = "Item.findByItemNameAndCountry", query = "SELECT  i FROM Item i WHERE i.itemName = :itemName AND i.countryID=:countryID")
})
public class Item implements Serializable {

    @JoinColumn(name = "factoryID", referencedColumnName = "idFactory")
    @ManyToOne
    private Factory factoryID;
    @JoinColumn(name = "countryID", referencedColumnName = "idcountry")
    @ManyToOne
    private Country countryID;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idItem")
    private Integer idItem;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "itemName")
    private String itemName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "itemType")
    private int itemType;
    @OneToMany(mappedBy = "itemID")
    private Collection<ExporterItem> exporterItemCollection;
    @OneToMany(mappedBy = "itemID")
    private Collection<BillItem> billItemCollection;
    // quantity and amount added to Item friday 17/8/2012
    @Column(name = "pK_count")

    private Double pk_Count = 0.0;
    @Column(name = "quantity")
    private Double quantity = 0.0;

    public Item() {
    }

    public Item(Integer idItem) {
        this.idItem = idItem;
    }

    public Item(Integer idItem, String itemName, int itemType) {
        this.idItem = idItem;
        this.itemName = itemName;
        this.itemType = itemType;
    }

    public Integer getIdItem() {
        return idItem;
    }

    public void setIdItem(Integer idItem) {
        this.idItem = idItem;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public int getItemType() {
        return itemType;
    }

    public void setItemType(int itemType) {
        this.itemType = itemType;
    }

    @XmlTransient
    public Collection<ExporterItem> getExporterItemCollection() {
        return exporterItemCollection;
    }

    public void setExporterItemCollection(Collection<ExporterItem> exporterItemCollection) {
        this.exporterItemCollection = exporterItemCollection;
    }

    @XmlTransient
    public Collection<BillItem> getBillItemCollection() {
        return billItemCollection;
    }

    public void setBillItemCollection(Collection<BillItem> billItemCollection) {
        this.billItemCollection = billItemCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idItem != null ? idItem.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Item)) {
            return false;
        }
        Item other = (Item) object;
        if ((this.idItem == null && other.idItem != null) || (this.idItem != null && !this.idItem.equals(other.idItem))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return idItem + "";
    }

    public Factory getFactoryID() {
        return factoryID;
    }

    public void setFactoryID(Factory factoryID) {
        this.factoryID = factoryID;
    }

    public Country getCountryID() {
        return countryID;
    }

    public void setCountryID(Country countryID) {
        this.countryID = countryID;
    }

    public Double getPk_Count() {
        return pk_Count;
    }

    public void setPk_Count(Double amount) {
        this.pk_Count = amount;
    }

    public Double getQuantity() {
        return quantity;
    }

    public void setQuantity(Double quantity) {
        this.quantity = quantity;
    }
}
